
from pysqlite2 import dbapi2 as sqlite

class Doctor:
	def __init__(self):
		self.db = sqlite.connect("splog.sql")
		if self.db:
			print "Connect db Success"
		else:
			print "Error connecting up db"
		cur = self.db.cursor()
		cur.execute("select * from doctors order by doctorID")
		self.rowcount = 0
		for row in cur:
			self.rowcount += 1
		self.rowcount += 1
		print self.rowcount	
		
			
	def load(self):
		pass
		
	def add(self, firstName_, lastName_):
		doctor = (self.getNextID(), firstName_, lastName_)
		cur = self.db.cursor()
		cur.execute("insert into doctors (doctorID, doctorFirstName, doctorLastName) values (?, ?, ?)", doctor)
		self.db.commit()
		
	def remove(self, id_):
		cur = self.db.cursor()
		queryFind = "select * from doctors where doctorID = " + str(id_)
		queryDel = "delete from doctors where doctorID = " + str(id_)
		cur.execute(queryFind)
		for row in cur:
			print row
		cur.execute(queryDel)
		self.db.commit()
		
		
	def reInitDb(self):
		cur = self.db.cursor()
		query = """
			CREATE TABLE [doctors] (
				[doctorID] INTEGER  NOT NULL PRIMARY KEY,
				[doctorFirstName] varchar(20)  NOT NULL,
				[doctorLastName] varchar(20)  NOT NULL
			)"""
		cur.execute(query)
		
	def getNextID(self):
		self.rowcount += 1
		return self.rowcount
		
	def getData(self):
		list = []
		cur = self.db.cursor()
		cur.execute("select * from doctors order by doctorID")
		for row in cur:
			list.append(row)
		return list